#!perl -w

use Parse::RecDescent;

#$::RD_WARN = 1;
#$::RD_ERRORS = 1;

$parser = new Parse::RecDescent <<'EOG';

<autotree>
script: statement_list end_of_source {$item[1]} | <error>
statement_list: statement(s) | <error>
statement: block
         | expression ';'
		 | conditional
         | ';'
 | <error>
		
block: '{' statement_list '}' | <error>

expression: mudcommand
          | string
          | <error>

mudcommand: '<' expression '>' {$item[2]} | <error>

conditional: cond_label '(' expression ')' statement

cond_label: 'if' | 'unless' | 'while' | 'until'

end_of_source: /\Z/ | <error>

string: '"' /[^"]*/ '"' {$item[2]}
      | "'" /[^']*/ "'" {$item[2]}

EOG

myprintree($parser->script(<<'EOS'), '');
<"look self">;
<"look room">;
"abc";
EOS

sub myprintree {
  my ($thing, $indent) = @_;
  if ($thing =~ 'HASH') {
    print "$indent\{\n";
    foreach (keys %$thing) {
      print "$indent  $_ => ";
      myprintree($thing->{$_}, "  $indent");
    }
    print "$indent\}\n";
  } elsif ($thing =~ 'ARRAY') {
    print "[\n";
    foreach (@$thing) {
      myprintree($_, "  $indent");
    }
    print "$indent\]\n";
  } else {
    print $thing, "\n";
  }
}